import QQMapWX from '@/common/qqmap-wx-jssdk.min.js'
import { mapMutations } from 'vuex'

export default {
  methods: {
    ...mapMutations('user', ['SET_U_ADDRESS']),
    getLocation() {
      uni.getLocation({
        type: 'gcj02',
        geocode: true,
        success: res => {
          let qqmapsdk = new QQMapWX({
            key: 'OZIBZ-IKMHQ-24G57-4AKLP-CZCD3-7BB4W',
          })
          qqmapsdk.reverseGeocoder({
            location: {
              latitude: res.latitude,
              longitude: res.longitude,
            },
            success: re => {
              this.SET_U_ADDRESS({
                name: re.result.address,
                latitude: res.latitude,
                longitude: res.longitude,
              })
            },
            fail: err => {
              console.log('位置获取失败====', err)
            },
          })
        },
        fail: err => {
          console.log('位置获取失败====', err)
        },
      })
    },
  },
}
